package com.foreveross.taskservice.core.domain.task;

import java.util.Date;
import java.util.UUID;

import javax.persistence.Column;

import org.openkoala.koala.commons.domain.KoalaUUIDAbstractEntity;

import com.foreveross.taskservice.common.GlobalsConst;
import com.foreveross.taskservice.common.TaskStatusEnum;

/**
 * 抓取任务执行日志记录
 * <p>
 * 在<@link>TaskQueueEntity</link>队列执行过程中，每一个队列每执行一次产生一条日志记录
 * 
 * @author xiangsf 2013-2-17
 * 
 */
@javax.persistence.Table(name = "CRAWL_TASK_QUEUE_LOG")
@javax.persistence.Entity
public class TaskQueueRecordEntity extends KoalaUUIDAbstractEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7924245433935886065L;
	@javax.persistence.Id
	@javax.persistence.Column(name = "id", length = 32)
	@javax.persistence.GeneratedValue(generator = "system-uuid")
	@org.hibernate.annotations.GenericGenerator(name = "system-uuid", strategy = "uuid")
	private String id;

	@Column(name = "task_id")
	private String taskId;

	@Column(name = "status")
	private int status = TaskStatusEnum.TASK_SUCCESS.getStatus();

	@Column(name = "create_date")
	private Date createTime = new Date();

	@Column(name = "start_time")
	private Date startTime;

	@Column(name = "end_time")
	private Date endTime;

	@Column(name = "plan_end_time")
	private Date planEndTime;// 计划结束时间，意思是过了这个时间就当任务是超时的了

	@Column(name = "remarks")
	private String remarks;

	@Column(name = "record_name")
	private String recordName;

	/**
	 * 抓取的航班数量
	 */
	@Column(name = "crawl_count")
	private int crawlCount = 0;
	/**
	 * 任务补偿次数
	 */
	@Column(name = "task_compensate_count")
	private int taskCompensateCount;
	/**
	 * 同一个任务的抓取次数
	 */
	@Column(name = "GRAD_TIMES")
	private int grabTimes = 0;

	@Column(name = "from_city")
	private String fromCity;

	@Column(name = "from_city_name")
	private String fromCityName;

	@Column(name = "to_city")
	private String toCity;

	@Column(name = "to_city_name")
	private String toCityName;

	@Column(name = "flight_date")
	private String flightDate;

	@Column(name = "grab_channel")
	private String grabChannel;

	@Column(name = "thread_name")
	private String threadName;

	@Column(name = "proxy_ip")
	private String proxyIp;

	/**
	 * 每条任务的流量统计
	 */
	@Column(name = "byte_length")
	private long byteLength;

	/**
	 * 起点城市区域码
	 */
	@Column(name = "area_code")
	private String areaCode;
	/**
	 * 起点城市区域名称
	 */
	@Column(name = "area_name")
	private String areaName;

	/**
	 * 附加的hbase应用值，用于生成rowkey,以便于应用根据该值统计
	 * <p>
	 * 实际上使用下面的"抓取渠道ID"也可，但基于应用已完成部分功能，补充上该值
	 */
	@Column(name = "attach_hbase_key")
	private String attachHbaseKey;

	/**
	 * 是否抓取回程,0代表否，1代表是
	 */
	@Column(name = "is_return")
	private int isReturn = GlobalsConst.DATA_LOGIC_N;

	// 返程日期
	@Column(name = "return_grab_date")
	private String returnGrabDate;

	/**
	 * 是否属于国际航线
	 */
	@Column(name = "IS_INTERNATIONAL")
	private int isInternational;

	// 优先级
	@Column(name = "priority")
	private int priority;

	/**
	 * 获取代理ip花费时间
	 */
	@Column(name = "proxy_ip_duration_time")
	private long proxyIpDurationTime = 0L;
	/**
	 * 抓取源网页内容花费时间
	 */
	@Column(name = "crawl_duration_time")
	private long crawlDurationTime = 0L;
	/**
	 * 解析源网页内容花费时间
	 */
	@Column(name = "parse_duration_time")
	private long parseDurationTime = 0L;
	/**
	 * 存储解析后内容花费时间
	 */
	@Column(name = "store_duration_time")
	private long storeDurationTime = 0L;
	/**
	 * 存储在hbase中的源网页数据rowkey值
	 */
	@Column(name = "source_rowkey")
	private String sourceRowkey;
	/**
	 * 存储在hbase中的源网页数据的大小
	 */
	@Column(name = "source_data_size")
	private int sourceDataSize = 0;

	// 抓取渠道ID
	@Column(name = "GRAB_CHANNEL_ID")
	private long grabChannelId;

	public TaskQueueRecordEntity() {
		
	}

	public TaskQueueRecordEntity(String fromCity, String fromCityName,
			String toCity, String toCityName, String flightDate,
			String returnGrabDate, int isInternational, int isReturn,
			long grabChannelId, String grabChannel, String areaCode,
			String areaName, String attachHbaseKey, int priority) {
		super();
		this.id = UUID.randomUUID().toString();
		this.fromCity = fromCity;
		this.fromCityName = fromCityName;
		this.toCity = toCity;
		this.toCityName = toCityName;
		this.flightDate = flightDate;
		this.returnGrabDate = returnGrabDate;
		this.isInternational = isInternational;
		this.isReturn = isReturn;
		this.grabChannelId = grabChannelId;
		this.grabChannel = grabChannel;
		this.areaCode = areaCode;
		this.areaName = areaName;
		this.attachHbaseKey = attachHbaseKey;
		this.priority = priority;
		this.status = TaskStatusEnum.TASK_WATI.getStatus();
		this.createTime = new Date();
		this.startTime = new Date();
	}

	@Override
	public String[] businessKeys() {
		return new String[] { getClass().getName() + id };
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTaskId() {
		return taskId;
	}

	public void setTaskId(String taskId) {
		this.taskId = taskId;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public Date getPlanEndTime() {
		return planEndTime;
	}

	public void setPlanEndTime(Date planEndTime) {
		this.planEndTime = planEndTime;
	}

	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	public String getRecordName() {
		return recordName;
	}

	public void setRecordName(String recordName) {
		this.recordName = recordName;
	}

	public int getCrawlCount() {
		return crawlCount;
	}

	public void setCrawlCount(int crawlCount) {
		this.crawlCount = crawlCount;
	}

	public int getTaskCompensateCount() {
		return taskCompensateCount;
	}

	public void setTaskCompensateCount(int taskCompensateCount) {
		this.taskCompensateCount = taskCompensateCount;
	}

	public int getGrabTimes() {
		return grabTimes;
	}

	public void setGrabTimes(int grabTimes) {
		this.grabTimes = grabTimes;
	}

	public String getFromCity() {
		return fromCity;
	}

	public void setFromCity(String fromCity) {
		this.fromCity = fromCity;
	}

	public String getFromCityName() {
		return fromCityName;
	}

	public void setFromCityName(String fromCityName) {
		this.fromCityName = fromCityName;
	}

	public String getToCity() {
		return toCity;
	}

	public void setToCity(String toCity) {
		this.toCity = toCity;
	}

	public String getToCityName() {
		return toCityName;
	}

	public void setToCityName(String toCityName) {
		this.toCityName = toCityName;
	}

	public String getFlightDate() {
		return flightDate;
	}

	public void setFlightDate(String flightDate) {
		this.flightDate = flightDate;
	}

	public String getGrabChannel() {
		return grabChannel;
	}

	public void setGrabChannel(String grabChannel) {
		this.grabChannel = grabChannel;
	}

	public String getThreadName() {
		return threadName;
	}

	public void setThreadName(String threadName) {
		this.threadName = threadName;
	}

	public String getProxyIp() {
		return proxyIp;
	}

	public void setProxyIp(String proxyIp) {
		this.proxyIp = proxyIp;
	}

	public long getByteLength() {
		return byteLength;
	}

	public void setByteLength(long byteLength) {
		this.byteLength = byteLength;
	}

	public String getAreaCode() {
		return areaCode;
	}

	public void setAreaCode(String areaCode) {
		this.areaCode = areaCode;
	}

	public String getAreaName() {
		return areaName;
	}

	public void setAreaName(String areaName) {
		this.areaName = areaName;
	}

	public String getAttachHbaseKey() {
		return attachHbaseKey;
	}

	public void setAttachHbaseKey(String attachHbaseKey) {
		this.attachHbaseKey = attachHbaseKey;
	}

	public int getIsReturn() {
		return isReturn;
	}

	public void setIsReturn(int isReturn) {
		this.isReturn = isReturn;
	}

	public String getReturnGrabDate() {
		return returnGrabDate;
	}

	public void setReturnGrabDate(String returnGrabDate) {
		this.returnGrabDate = returnGrabDate;
	}

	public int getIsInternational() {
		return isInternational;
	}

	public void setIsInternational(int isInternational) {
		this.isInternational = isInternational;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public long getProxyIpDurationTime() {
		return proxyIpDurationTime;
	}

	public void setProxyIpDurationTime(long proxyIpDurationTime) {
		this.proxyIpDurationTime = proxyIpDurationTime;
	}

	public long getCrawlDurationTime() {
		return crawlDurationTime;
	}

	public void setCrawlDurationTime(long crawlDurationTime) {
		this.crawlDurationTime = crawlDurationTime;
	}

	public long getParseDurationTime() {
		return parseDurationTime;
	}

	public void setParseDurationTime(long parseDurationTime) {
		this.parseDurationTime = parseDurationTime;
	}

	public long getStoreDurationTime() {
		return storeDurationTime;
	}

	public void setStoreDurationTime(long storeDurationTime) {
		this.storeDurationTime = storeDurationTime;
	}

	public String getSourceRowkey() {
		return sourceRowkey;
	}

	public void setSourceRowkey(String sourceRowkey) {
		this.sourceRowkey = sourceRowkey;
	}

	public int getSourceDataSize() {
		return sourceDataSize;
	}

	public void setSourceDataSize(int sourceDataSize) {
		this.sourceDataSize = sourceDataSize;
	}

	public long getGrabChannelId() {
		return grabChannelId;
	}

	public void setGrabChannelId(long grabChannelId) {
		this.grabChannelId = grabChannelId;
	}
	
	
	
	
	
	
	
}
